﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.IO;

namespace YouHP.Pages
{
    public class ViewDisease : BasePage
    {
        public DiseaseInfo mDiseaseInfo;
        public List<DiseaseStatRegionInfo> mStatRegion;
        public List<DiseaseStatAgeInfo> mStatAge;
        public List<DiseaseStatDurationInfo> mStatDuration;
        public List<DiseaseStatSymptomInfo> mStatSymptom;
        public List<DiseaseStatTreamentInfo> mStatTreament;

        protected override void ShowPage()
        {

            int did = RequestTools.GetQueryInt("id", -1);
            if (did == -1)
            {
                this.AddErrLine("找不到疾病");
                return;
            }

            mDiseaseInfo = DiseaseBLL.Instance.GetDiseaseInfo(did);
            string path = Utils.GetMapPath(string.Format("~/datafiles/disease/{0}", did));
            if (Directory.Exists(path) == false) Directory.CreateDirectory(path);
            string filename = Path.Combine(path, "region.txt");
            if (File.Exists(filename) == false)
            {
                mStatRegion = DiseaseBLL.Instance.GetDiseaseStatRegion(did, 0);
                StreamWriter writter = new StreamWriter(filename, false);
                writter.WriteLine("&title=疾病地区分布,{font-size:12px; color:#000000}&");
                writter.WriteLine("&pie=60,#9933CC,{display: n-one; font-size:16px; color: #ff0000;},false,3&");
                int cnt = 0;
                foreach (DiseaseStatRegionInfo info in mStatRegion)
                {
                    cnt += info.PatientCount;
                }
                if (cnt == 0) cnt = 1;

                string values = "&values=";
                string labels = "&pie_labels=";
                string links = "&links=";
                foreach (DiseaseStatRegionInfo info in mStatRegion)
                {
                    values += string.Format(",{0:F2}", info.PatientCount * 100.0 / cnt);
                    labels += string.Format(",{0}", info.RegionName);
                    links += string.Format(",javascript:alert('{0}')", info.RegionId);
                }
                values += "&";
                labels += "&";
                links += "&";
                writter.WriteLine(values);
                writter.WriteLine(labels);
                writter.WriteLine(links);

                writter.Close();
            }
            

            //mStatSymptom = DiseaseBLL.Instance.GetDiseaseStatSymptom(did);
            //mStatTreament = DiseaseBLL.Instance.GetDiseaseStatTreament(did);
            //mStatDuration = DiseaseBLL.Instance.GetDiseaseStatDuration(did);
            //mStatAge = DiseaseBLL.Instance.GetDiseaseStatAge(did);

            //this.SeoTitle = mDiseaseInfo.Name;
            this.PageTitle = "疾病";
        }
    }
}
